#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <assert.h>
#include <ctype.h>
#include <limits.h>

int my_atoi(const char* str)
{
	assert(str != NULL);
	if (*str == '\0')
	{
		return 0;
	}
	while (isspace(*str))
	{
		str++;
	}
	int flag = 0;
	if (*str == '-')
	{
		flag = -1;
		str++;
	}
	else
	{
		flag = 1;
		str++;
	}
	long long ret = 0;
	while (*str != '\0')
	{
		if (isdigit(*str))
		{
			ret = ret * 10 + flag * (*str - '0');
			str++;
			if (ret > INT_MAX)
				return INT_MAX;
			else if (ret < INT_MIN)
				return INT_MIN;
		}
		else
		{
			return ret;
		}
	}
	return (int)ret;
}
int main()
{
	const char* str = "  -1235554566656";
	int ret = my_atoi(str);
	printf("%d\n", ret);
	return 0;
}